package com.lz.autotest.project.testmanage.autoTest.service.Listener;

import com.lz.autotest.common.utils.GlobalMap;
import com.lz.autotest.project.testmanage.reportmanage.domain.SstReportItem;

import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author: X
 * @date: Created in 2023/7/12 9:27
 * @Description: 获取计算引擎性能信息
 */
public class CalcServiceListener extends Listener  {

    public CalcServiceListener(String listenerType, Integer priority) {
        super(listenerType, priority);
    }

    @Override
    public void execute(Map<String, Object> map) {
        SstReportItem sstInfReport = (SstReportItem) map.get("msg");
        GlobalMap.get(sstInfReport.getReportId()).getAndIncrement();
        if (GlobalMap.get(sstInfReport.getReportId()).get() == new AtomicInteger((int)sstInfReport.getConcurrency()).get()) {
            GlobalMap.remove(sstInfReport.getReportId());
            GlobalMap.get(sstInfReport.getReportId());
            GlobalMap.removeEnv(sstInfReport.getReportId());
        }
    }
}
